//package com.site.springboot.core.controller.admin;
//
//import com.site.springboot.core.entity.AuthRequest;
//import com.site.springboot.core.filter.JwtAuthenticationTokenFilter;
//import com.site.springboot.core.service.impl.JwtService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.authentication.AuthenticationManager;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.HashMap;
//
///**
// * Project:springboot-project-news-publish-system
// * ClassName:LoginController
// * Package:com.site.springboot.core.controller.admin
// * User:CWQ
// * Description:
// *
// * @Author 合肥-陈万琼
// * @Create 2024/5/30 21:14
// * @Version 1.0
// */
//@RestController
//@RequestMapping("/admin")
//public class LoginController {
//    @Autowired
//    private AuthenticationManager authenticationManager;
//    @Autowired
//    private JwtService jwtService;
//    @PostMapping("/token")
//    public HashMap<String, Object> authenticateAndGetToken(@RequestBody AuthRequest authRequest) {
//        String username = authRequest.getUsername();
//        String password = authRequest.getPassword();
//
//        System.out.println("调用了");
//        System.out.println("传进来的用户名称为" + username);
//        Authentication authentication = null;
//        try {
//            authentication = authenticationManager.authenticate(
//                    new UsernamePasswordAuthenticationToken(username, password));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        if (authentication.isAuthenticated()) {
//            String token = jwtService.generateToken(username);
//            System.out.println("JWT为" + token);
//            return new HashMap<String, Object> () {
//                {
//                    put("token", token);
//                    put("success", 200);
//                }
//            };
//        } else {
//            throw new UsernameNotFoundException("用户名或密码错误");
//        }
//    }
//}
